package com.smartodo.web.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.owasp.esapi.ESAPI;

/**
 * @author Pawan Singh
 * Servlet implementation class for Servlet: Main
 *
 */
 public class Main extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public Main() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
//		HttpSession session = request.getSession();
//		String JSessionId = session.getId();
//		
//		 String sessionIdCookie = null;
//		 Cookie[] cookies = request.getCookies();
//		 if (cookies != null) {
//			 for (int i = 1; i < cookies.length; i++) {
//				 if ("JSessionId".equals(cookies[i].getName())) {
//					 sessionIdCookie = cookies[i].getValue();
//				 }
//			 }
//		 }
//		 
//		System.out.println("@PAwan"+JSessionId.equals(sessionIdCookie));
//		System.out.println(sessionIdCookie);
//		System.out.println(JSessionId);
//		 
//		if(JSessionId.equals(sessionIdCookie)) {
			RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/main.jsp");
			dispatcher.forward(request, response);
			return;
//		} else {
//			RequestDispatcher dispatcher = request.getRequestDispatcher("WEB-INF/jsp/home.jsp");
//			dispatcher.forward(request, response);
//			return;
//		}
	}   	  	    
}